package com.itheima.service;

import com.fasterxml.jackson.annotation.JsonRawValue;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.EmpService;
import com.itheima.mapper.EmpExprMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpExpr;
import com.itheima.pojo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
@Autowired
private EmpExprMapper empExprMapper;
    //    @Override
//    public PageResult<Emp> findPage(Integer page, Integer pageSize) {
//          Long total = empMapper.findCount();
//
//          Integer skip = (page-1) * pageSize;
//            List<Emp> rows   = empMapper.find Page(skip,page);
//        return new PageResult(total,rows)  ;
//        PageHelper.startPage(page,pageSize);
//        Page<Emp> page1=(Page<Emp>) empMapper.list();
//        long total = page1.getTotal();
//        List<Emp> rows = page1.getResult();
//        return new PageResult(total,rows);
    @Override
    public PageResult<Emp> findPage(Integer page, Integer pageSize, String name, Integer gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page, pageSize);
        Page<Emp> page1 = (Page<Emp>) empMapper.list(name, gender, begin, end);
        long total = page1.getTotal();
        List<Emp> rows = page1.getResult();
        return new PageResult(total, rows);
    }


    }



